var status_code = function (code) {
  //权限
  switch (code) {
    case 10002:
      return "你没有该操作权限";
      break;
    case 10000:
      return "你的账户已过期，或在异地登录，请重新登陆";
      break;
    default:
      return true
  }
};
var dataSuccess = function (val, this_) {
  //成功的返回
  switch (val.status_code) {
    case 200:
      this_.$notify({
        title: '成功',
        message: val.Massage,
        type: 'success'
      });
      break;
    case 2:
      // console.log(123);
      break;
  }
};
var formattime = function (time) {
  //设置时间
  let endTime = new Date(time);
  var hour = endTime.getHours() < 10 ? "0" + endTime.getHours() : endTime.getHours();
  var minute = endTime.getMinutes() < 10 ? "0" + endTime.getMinutes() : endTime.getMinutes();
  var second = endTime.getSeconds() < 10 ? "0" + endTime.getSeconds() : endTime.getSeconds();
  return `${endTime.getFullYear()}年${endTime.getMonth() + 1}月${endTime.getDate()}日:${hour}时-${minute}分-${second}秒`
};
var SetStorage = function (k, v) {
  //添加 localStorage
  window.localStorage.removeItem(k);
  window.localStorage.setItem(k, v);
};
var GetStorage = function (k) {
  //读取 localStorage
  return window.localStorage.getItem(k);
};
var Ed = function (val, this_) {
  //分返错误
  this_.$notify.error({
    title: '错误',
    message: val.response.data.Massage
  });
}.bind(this);
// var exportexcel = function (herder, value, dataval, text) {
//   //表格下载
//   const {export_json_to_excel} = require('../vendor/Export2Excel');
//   require.ensure([], () => {
//     const tHeader = herder;
//     const filterVal = value;
//     const list = dataval;
//     const data = this.formatJson(filterVal, list);
//     export_json_to_excel(tHeader, data, text);
//   })
// };

// var formatJson = function (filterVal, jsonData) {
//   return jsonData.map(v => filterVal.map(j => v[j]))
// };
var userphone_test = function (val, this_) {
  //电话号码正则
  var reg = /^[1-9]\d*$|^0$/;
  if (reg.test(val) == true) {
    if (val.length == 11) {
      return true;
    } else {
      this_.$notify.error({
        title: '错误',
        message: '您输入的电话号码长度不正确'
      });
    }
  } else {
    this_.$notify.error({
      title: '错误',
      message: '您输入的格式不正确！'
    });
  }
};


var user_type = function (type) {
  //角色过滤
  switch (type) {
    case 1:
      return "管理员";
      break;
    case 2:
      return "员工";
      break;
    case 3:
      return "一级代理商";
      break;
    case 4:
      return "二级代理商";
      break;
    case 5:
      return "用户";
      break;
  }
};
var nueTime = function (time1) {
  // 获取时间
  var start = time1;
  var statea = start.getMonth() + 1;
  var starttime = start.getFullYear() + '-' + (this.Appendzero(statea)) + '-' + this.Appendzero(start.getDate()) + 'T' + this.Appendzero(start.getHours()) + ':' + this.Appendzero(start.getMinutes()) + ':' + this.Appendzero(start.getSeconds());
  return starttime;
};
var TwoNueTime = function (time1, time2) {
  // 获取时间
  var start = time1;
  var End = time2;
  var statea = start.getMonth() + 1;
  var starttime = start.getFullYear() + '-' + (this.Appendzero(statea)) + '-' + this.Appendzero(start.getDate()) + ' ' + '00' + ':' + '00' + ':' + '00';
  var endstate = End.getMonth() + 1;
  var Endtime = End.getFullYear() + '-' + (this.Appendzero(endstate)) + '-' + this.Appendzero(End.getDate()) + ' ' + 23 + ':' + 59 + ':' + '59';
  return [starttime, Endtime];
}
var Appendzero = function (obj) {
  ////  日期 不够两位数 就在前面加一个0
  if (obj < 10) return "0" + "" + obj;
  else return obj;
};
var number_two = function (num) {
  //小数点后保留2位
  let v =num * 1;
  return v.toFixed(2)
  // return parseInt(num * 100) / 100;
};

var Pc_Client = function () {
  //判断是客户端还是PC
  var sUserAgent = navigator.userAgent.toLowerCase();
  var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
  var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
  var bIsMidp = sUserAgent.match(/midp/i) == "midp";
  var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
  var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
  var bIsAndroid = sUserAgent.match(/android/i) == "android";
  var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
  var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
  if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM)) {
    return 'PC';
  } else {
    return 'Client';
  }
};

var weiixn_open = function () {
  //微信浏览器打开
  // <head>
  //   <meta charset="utf-8">
  //   <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
  // </head>
  var ua = navigator.userAgent.toLowerCase();
  var isWeixin = ua.indexOf('micromessenger') != -1;
  var isAndroid = ua.indexOf('android') != -1;
  var isIos = (ua.indexOf('iphone') != -1) || (ua.indexOf('ipad') != -1);
  if (!isWeixin) {
    document.head.innerHTML = '<title>抱歉，出错了</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" >';
    document.body.innerHTML = '<div class="weui_msg"><div class="weui_icon_area"><i class="weui_icon_info weui_icon_msg"></i></div><div class="weui_text_area"><h4 class="weui_msg_title">请在微信客户端打开链接</h4></div></div>';
  }
  else {
    document.head.innerHTML = '<title>在微信打开</title><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0"><link rel="stylesheet" type="text/css" >';
    document.body.innerHTML = '打开成功！';
  }
}


export default{
  status_code,//权限
  dataSuccess,  //成功的返回
  formattime,//设置时间
  SetStorage,//添加 localStorage
  GetStorage,  //读取 localStorage
  // exportexcel,  //表格下载
  // formatJson,  //表格下载
  Ed,          //分返错误
  user_type,  //角色过滤
  userphone_test, //电话号码正则
  nueTime,    // 获取时间
  TwoNueTime,//两个时间
  Appendzero,// 获取时间
  number_two,//小数点后保留2位
  Pc_Client,//判断是客户端还是手机端
  weiixn_open,//微信浏览器打开
};
